home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Extras / Development / Example_Code_v37 / Libraries / Intuition / boopsi / pubi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-27  |  2.6 KB  |  112 lines

  1.  
  2. /* pubi.c -- :ts=8
  3.  * installation of public image class by
  4.  * program (probably run in background)
  5.  * you type control-C to get this one to
  6.  * try to free its class and exit.
  7.  */
  8.  
  9. /*
  10. Copyright (c) 1989-1999 Amiga, Inc.
  11.  
  12. Executables based on this information may be used in software
  13. for Amiga computers. All other rights reserved.
  14. This information is provided "as is"; no warranties are made.
  15. All use is at your own risk, and no liability or responsibility
  16. is assumed.
  17. */
  18.  
  19. #include "sysall.h"
  20. #include <dos/dos.h>
  21.  
  22. #define D(x)    x
  23.  
  24. struct  IntuitionBase   *IntuitionBase;
  25. struct  GfxBase         *GfxBase;
  26. struct  Library         *UtilityBase;
  27.  
  28. /* class pointer is an abstract handle, which
  29.  * one never uses for "public" access to a class,
  30.  * but we as class owner can use for private access,
  31.  * or to free the class.
  32.  */
  33. void    *initEmbBClass();
  34. void    *EmbBClass;
  35.  
  36. struct EasyStruct myez = { sizeof (struct EasyStruct), 0,
  37.     "Emboxclass Installer",
  38.     "Cannot remove 'emboxclass'.",
  39.     "Retry|Private|Public",
  40. };
  41.  
  42. main()
  43. {
  44.     openAll();    /* get libraries open    */
  45.  
  46.     /* init the public class    */
  47.     EmbBClass = initEmbBClass();
  48.  
  49.     D( kprintf("class is initialized\n") );
  50.  
  51.     printf("Class initialized, break ^C to terminate.\n");
  52.  
  53.     /* take a shot at removing it when we get a Break signal */
  54.     for( Wait( SIGBREAKF_CTRL_C );; )
  55.     {
  56.         D( kprintf("try to free class\n") );
  57.  
  58.     /* quit if class can be freed    */
  59.     if (  freeEmbBClass( EmbBClass ) )
  60.     {
  61.         D( kprintf("FreeClass succeeded\n") );
  62.         break;
  63.     }
  64.  
  65.     switch ( EasyRequest( NULL, &myez, 0 ) )
  66.     {
  67.     case 1:    /* retry without waiting    */
  68.         D( kprintf("retry free\n") );
  69.         continue;
  70.  
  71.     default:
  72.         D( kprintf("default request return\n") );
  73.     case 0:        /* public: add, and wait    */
  74.         D( kprintf("add class back in\n") );
  75.         AddClass( EmbBClass );
  76.     case 2:        /* private: just go wait some more    */
  77.         break;
  78.     }
  79.  
  80.     D( kprintf("wait for break again\n") );
  81.     Wait( SIGBREAKF_CTRL_C );
  82.    }
  83.  
  84.     cleanup( "all done" );
  85. }
  86.  
  87. cleanup( str )
  88. char    *str;
  89. {
  90.     if (str) printf("%s\n", str);
  91.  
  92.     if (IntuitionBase) CloseLibrary(IntuitionBase);
  93.     if (GfxBase) CloseLibrary(GfxBase);
  94.     if (UtilityBase) CloseLibrary(UtilityBase);
  95.  
  96.     exit (0);
  97. }
  98.  
  99. /* exits via cleanup() if failure    */
  100. openAll()
  101. {
  102.     if (!(UtilityBase=(struct Library *)OpenLibrary("utility.library",36L)))
  103.     { cleanup("no V36 utility library\n"); }
  104.  
  105.     if (!(IntuitionBase =
  106.     (struct IntuitionBase *) OpenLibrary("intuition.library", 36L)))
  107.     { cleanup("no V36 intuition library\n"); }
  108.  
  109.     if (!(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 36L)))
  110.     { cleanup("no V36 graphics library\n"); }
  111. }
  112.